package aes.client;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.table.*;

import common.*;

public class ExamEditorUI extends JPanel implements ActionListener, ListSelectionListener, Observer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2728459188427285381L;
	
	private ClientUI ui;
	private Client c;
	private int eId = 0;
	
	private JButton btnCancel;
	private JButton btnSave;
	private JTextField txtSolveTime;
	private JTextField txtTeacherComments;
	private JTextField txtStudentsComments;
	private JComboBox cmbSubject;
	private JComboBox cmbCourse;
	private JTable table;
	private JTextField txtExamNum;
	private JButton btnRemoveQuestion;
	private JButton btnAddQuestion;
	private JLabel lblWarning;
	
	/**
	 * Constructor
	 * @param c Client object
	 * @param ui ClientUI object
	 */
	public ExamEditorUI(Client c,ClientUI ui) {
		super();
		this.c = c;
		this.ui = ui;
		JFrame frame = new JFrame();
		frame.setSize(640, 480);
		frame.getContentPane().add(this);
		
		c.addObserver(this);
		setLayout(new GridBagLayout());

		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(new Color(0, 0, 0), 2, true));
		panel.setPreferredSize(new Dimension(600,400));

		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(5, 0, 5, 0);
		gbc_panel.gridx = 0;
		gbc_panel.gridy = 0;
		add(panel,gbc_panel);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
		gbl_panel.columnWeights = new double[]{0.0, 1.0, 0.0};
		panel.setLayout(gbl_panel);

		JLabel lblAesTitle = new JLabel("Exams Editor");
		lblAesTitle.setVerticalAlignment(SwingConstants.TOP);
		lblAesTitle.setHorizontalAlignment(SwingConstants.CENTER);
		lblAesTitle.setBounds(7, 10, 70, 17);
		lblAesTitle.setFont(new Font("Tahoma", Font.BOLD, 14));

		GridBagConstraints gbc_lblAesTitle = new GridBagConstraints();
		gbc_lblAesTitle.anchor = GridBagConstraints.NORTH;
		gbc_lblAesTitle.gridwidth = 3;
		gbc_lblAesTitle.fill = GridBagConstraints.BOTH;
		gbc_lblAesTitle.insets = new Insets(5, 0, 5, 0);
		gbc_lblAesTitle.gridx = 0;
		gbc_lblAesTitle.gridy = 0;
		panel.add(lblAesTitle, gbc_lblAesTitle);
		
		JLabel lblSubject = new JLabel("Subject:");
		GridBagConstraints gbc_lblSubject = new GridBagConstraints();
		gbc_lblSubject.anchor = GridBagConstraints.EAST;
		gbc_lblSubject.insets = new Insets(0, 5, 5, 5);
		gbc_lblSubject.gridx = 0;
		gbc_lblSubject.gridy = 1;
		panel.add(lblSubject, gbc_lblSubject);
		
		cmbSubject = new JComboBox();
		GridBagConstraints gbc_cmbSubject = new GridBagConstraints();
		gbc_cmbSubject.insets = new Insets(0, 0, 5, 10);
		gbc_cmbSubject.fill = GridBagConstraints.HORIZONTAL;
		gbc_cmbSubject.gridwidth = 2;
		gbc_cmbSubject.gridx = 1;
		gbc_cmbSubject.gridy = 1;
		panel.add(cmbSubject, gbc_cmbSubject);
		
		JLabel lblCourse = new JLabel("Course:");
		GridBagConstraints gbc_lblCourse = new GridBagConstraints();
		gbc_lblCourse.anchor = GridBagConstraints.EAST;
		gbc_lblCourse.insets = new Insets(0, 5, 5, 5);
		gbc_lblCourse.gridx = 0;
		gbc_lblCourse.gridy = 2;
		panel.add(lblCourse, gbc_lblCourse);
		
		cmbCourse = new JComboBox();
		GridBagConstraints gbc_cmbCourse = new GridBagConstraints();
		gbc_cmbCourse.gridwidth = 2;
		gbc_cmbCourse.insets = new Insets(0, 0, 5, 10);
		gbc_cmbCourse.fill = GridBagConstraints.HORIZONTAL;
		gbc_cmbCourse.gridx = 1;
		gbc_cmbCourse.gridy = 2;
		panel.add(cmbCourse, gbc_cmbCourse);

		table = new JTable(){
			/**
			 * 
			 */
			private static final long serialVersionUID = 7458975972801695617L;

			public boolean isCellEditable(int rowIndex, int colIndex) {
				return false; //Disallow the editing of any cell
			}};
		table.setModel(new DefaultTableModel(
				new Object[][] {
				},
				new String[] {
						"Question #", "Subject", "Ponts", "Question", "ID"
				}
				) {
			/**
			 * 
			 */
			private static final long serialVersionUID = -4567261985989300298L;
			@SuppressWarnings("rawtypes")
			Class[] columnTypes = new Class[] {
				String.class, String.class, String.class , String.class , String.class 
			};
			@SuppressWarnings({ "unchecked", "rawtypes" })
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		table.removeColumn(table.getColumnModel().getColumn(4));
		JScrollPane scrollPane = new JScrollPane(table);
		table.setFillsViewportHeight(true);
		table.getSelectionModel().addListSelectionListener(this);
		
		JLabel lblExam = new JLabel("Exam #:");
		GridBagConstraints gbc_lblExam = new GridBagConstraints();
		gbc_lblExam.anchor = GridBagConstraints.EAST;
		gbc_lblExam.insets = new Insets(0, 5, 5, 5);
		gbc_lblExam.gridx = 0;
		gbc_lblExam.gridy = 3;
		panel.add(lblExam, gbc_lblExam);
		
		txtExamNum = new JTextField();
		GridBagConstraints gbc_txtExamNum = new GridBagConstraints();
		gbc_txtExamNum.gridwidth = 2;
		gbc_txtExamNum.insets = new Insets(0, 0, 5, 10);
		gbc_txtExamNum.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtExamNum.gridx = 1;
		gbc_txtExamNum.gridy = 3;
		panel.add(txtExamNum, gbc_txtExamNum);
		txtExamNum.setColumns(10);
		
		JLabel lblSolveTimemin = new JLabel("Solve Time (min):");
		GridBagConstraints gbc_lblSolveTimemin = new GridBagConstraints();
		gbc_lblSolveTimemin.anchor = GridBagConstraints.EAST;
		gbc_lblSolveTimemin.insets = new Insets(0, 5, 5, 5);
		gbc_lblSolveTimemin.gridx = 0;
		gbc_lblSolveTimemin.gridy = 4;
		panel.add(lblSolveTimemin, gbc_lblSolveTimemin);
		
		txtSolveTime = new JTextField();
		GridBagConstraints gbc_txtSolveTime = new GridBagConstraints();
		gbc_txtSolveTime.gridwidth = 2;
		gbc_txtSolveTime.anchor = GridBagConstraints.NORTH;
		gbc_txtSolveTime.insets = new Insets(0, 0, 5, 10);
		gbc_txtSolveTime.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtSolveTime.gridx = 1;
		gbc_txtSolveTime.gridy = 4;
		panel.add(txtSolveTime, gbc_txtSolveTime);
		txtSolveTime.setColumns(10);
		
		JLabel lblTeacherComments = new JLabel("Teacher Comments:");
		GridBagConstraints gbc_lblTeacherComments = new GridBagConstraints();
		gbc_lblTeacherComments.anchor = GridBagConstraints.EAST;
		gbc_lblTeacherComments.insets = new Insets(0, 5, 5, 5);
		gbc_lblTeacherComments.gridx = 0;
		gbc_lblTeacherComments.gridy = 5;
		panel.add(lblTeacherComments, gbc_lblTeacherComments);
		
		txtTeacherComments = new JTextField();
		GridBagConstraints gbc_txtTeacherComments = new GridBagConstraints();
		gbc_txtTeacherComments.gridwidth = 2;
		gbc_txtTeacherComments.insets = new Insets(0, 0, 5, 10);
		gbc_txtTeacherComments.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtTeacherComments.gridx = 1;
		gbc_txtTeacherComments.gridy = 5;
		panel.add(txtTeacherComments, gbc_txtTeacherComments);
		txtTeacherComments.setColumns(10);
		
		JLabel lblStudentsComments = new JLabel("Students Comments:");
		GridBagConstraints gbc_lblStudentsComments = new GridBagConstraints();
		gbc_lblStudentsComments.anchor = GridBagConstraints.EAST;
		gbc_lblStudentsComments.insets = new Insets(0, 5, 5, 5);
		gbc_lblStudentsComments.gridx = 0;
		gbc_lblStudentsComments.gridy = 6;
		panel.add(lblStudentsComments, gbc_lblStudentsComments);
		
		txtStudentsComments = new JTextField();
		GridBagConstraints gbc_txtStudentsComments = new GridBagConstraints();
		gbc_txtStudentsComments.gridwidth = 2;
		gbc_txtStudentsComments.anchor = GridBagConstraints.NORTH;
		gbc_txtStudentsComments.insets = new Insets(0, 0, 5, 10);
		gbc_txtStudentsComments.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtStudentsComments.gridx = 1;
		gbc_txtStudentsComments.gridy = 6;
		panel.add(txtStudentsComments, gbc_txtStudentsComments);
		txtStudentsComments.setColumns(10);
		
		JLabel lblQuestions = new JLabel("Questions:");
		GridBagConstraints gbc_lblQuestions = new GridBagConstraints();
		gbc_lblQuestions.anchor = GridBagConstraints.NORTHEAST;
		gbc_lblQuestions.insets = new Insets(0, 5, 5, 5);
		gbc_lblQuestions.gridx = 0;
		gbc_lblQuestions.gridy = 7;
		panel.add(lblQuestions, gbc_lblQuestions);
		GridBagConstraints gbc_table = new GridBagConstraints();
		gbc_table.gridwidth = 2;
		gbc_table.weighty = 100.0;
		gbc_table.insets = new Insets(0, 0, 5, 10);
		gbc_table.fill = GridBagConstraints.BOTH;
		gbc_table.gridx = 1;
		gbc_table.gridy = 7;
		panel.add(scrollPane, gbc_table);
		
		lblWarning = new JLabel("<html>Warning: You need to save exam before adding questions.</html>");
		lblWarning.setForeground(Color.RED);
		lblWarning.setFont(new Font("Tahoma", Font.PLAIN, 10));
		GridBagConstraints gbc_lblWarning = new GridBagConstraints();
		gbc_lblWarning.fill = GridBagConstraints.BOTH;
		gbc_lblWarning.insets = new Insets(0, 0, 5, 5);
		gbc_lblWarning.gridx = 1;
		gbc_lblWarning.gridy = 8;
		gbc_lblWarning.gridwidth = 2;
		panel.add(lblWarning, gbc_lblWarning);
		
		btnSave = new JButton("Save", new ImageIcon(ExamEditorUI.class.getResource("/aes/client/images/Save.png")));
		btnSave.addActionListener(this); 
		
		btnAddQuestion = new JButton("Add Question");
		btnAddQuestion.setIcon(new ImageIcon(ExamEditorUI.class.getResource("/aes/client/images/question_add.png")));
		btnAddQuestion.setHorizontalAlignment(SwingConstants.LEFT);
		btnAddQuestion.addActionListener(this); 
		
		GridBagConstraints gbc_btnAddQuestion = new GridBagConstraints();
		gbc_btnAddQuestion.anchor = GridBagConstraints.WEST;
		gbc_btnAddQuestion.insets = new Insets(0, 0, 5, 5);
		gbc_btnAddQuestion.gridx = 1;
		gbc_btnAddQuestion.gridy = 9;
		panel.add(btnAddQuestion, gbc_btnAddQuestion);
		
		btnRemoveQuestion = new JButton("Remove Question");
		btnRemoveQuestion.setHorizontalAlignment(SwingConstants.LEFT);
		btnRemoveQuestion.setIcon(new ImageIcon(ExamEditorUI.class.getResource("/aes/client/images/question_delete.png")));
		btnRemoveQuestion.addActionListener(this); 
		GridBagConstraints gbc_btnRemoveQuestion = new GridBagConstraints();
		gbc_btnRemoveQuestion.anchor = GridBagConstraints.WEST;
		gbc_btnRemoveQuestion.insets = new Insets(0, 0, 5, 10);
		gbc_btnRemoveQuestion.gridx = 2;
		gbc_btnRemoveQuestion.gridy = 9;
		panel.add(btnRemoveQuestion, gbc_btnRemoveQuestion);
		GridBagConstraints gbc_btnSave = new GridBagConstraints();
		gbc_btnSave.insets = new Insets(5, 5, 5, 5);
		gbc_btnSave.gridx = 0;
		gbc_btnSave.gridy = 10;
		panel.add(btnSave, gbc_btnSave);
		btnSave.setBounds(353, 7, 57, 23);
		
		btnCancel = new JButton("Cancel", new ImageIcon(ExamEditorUI.class.getResource("/aes/client/images/Cancel.png")));
		btnCancel.setHorizontalAlignment(SwingConstants.LEFT);
		btnCancel.addActionListener(this); 
		
		GridBagConstraints gbc_btnCancel = new GridBagConstraints();
		gbc_btnCancel.gridwidth = 2;
		gbc_btnCancel.anchor = GridBagConstraints.WEST;
		gbc_btnCancel.insets = new Insets(5, (ui.getUser() instanceof Principal)? 10 : 0, 5, 0);
		gbc_btnCancel.gridx = (ui.getUser() instanceof Principal)? 0 : 1;
		gbc_btnCancel.gridy = 10;
		panel.add(btnCancel, gbc_btnCancel);
		btnCancel.setBounds(353, 7, 57, 23);
		
		if (ui.getUser() instanceof Principal) {
			btnSave.setVisible(false);
			btnAddQuestion.setVisible(false);
			btnRemoveQuestion.setVisible(false);
			btnCancel.setIcon(new ImageIcon(QuestionsManagerUI.class.getResource("/aes/client/images/back.png")));
			btnCancel.setText("Back");
			
			txtExamNum.setEditable(false);
			txtSolveTime.setEditable(false);
			txtTeacherComments.setEditable(false);
			txtStudentsComments.setEditable(false);
			//txtAnswer4.setEditable(false);
			//cmbCorrectAnswer.setEnabled(false);
			//txtNotes.setEditable(false);
		}

		Initialize();
	}
	
	/**
	 * Loads comboboxes data
	 */
	private void Initialize() {
		btnAddQuestion.setEnabled(false);
		btnRemoveQuestion.setEnabled(false);
		// Get Subjects.
		CommandMessage msg = new CommandMessage(CommandMessage.GET_SUBJECTS, new Object[] {});
		try {
			c.sendToServer(msg);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Message received event handler
	 */
	@SuppressWarnings("static-access")
	@Override
	public void update(Observable arg0, Object arg1) {
		if (arg1 instanceof CommandMessage) {
			CommandMessage ms=(CommandMessage)arg1;
			if (ms.getCommand().equals(CommandMessage.ACKNOWLEDGE_MESSAGE) && ((String)ms.getParams()[0]).equals(CommandMessage.GET_SUBJECTS)) {
				// Subjects list updated.
				Subject[] subjects = (Subject[]) ms.getParams()[1];

				cmbSubject.removeAllItems();
				if(subjects!=null){
					for (Subject s:subjects) 
						cmbSubject.addItem(s);
				}
				
				// Get courses list.
				CommandMessage msg = new CommandMessage(CommandMessage.GET_COURSES, new Object[] {});
				try {
					c.sendToServer(msg);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (ms.getCommand().equals(CommandMessage.ACKNOWLEDGE_MESSAGE) && ((String)ms.getParams()[0]).equals(CommandMessage.GET_COURSES)) {
				// Courses list updated.
				Course[] courses = (Course[]) ms.getParams()[1];

				cmbCourse.removeAllItems();
				if(courses!=null){
					for (Course c:courses) 
						cmbCourse.addItem(c);
				}
			}
			if (ms.getCommand().equals(CommandMessage.ACKNOWLEDGE_MESSAGE) && ((String)ms.getParams()[0]).equals(CommandMessage.GET_EXAMS) && ms.getParams()[1] != null && ((String)ms.getParams()[1]).equals("ID")) {
				// Exam details received.
				if (ms.getParams() == null || ms.getParams().length < 3 || ms.getParams()[2] == null)
					ui.SetContent(ui.EXAMS_MANAGER_SCREEN);
				
				Exam[] tmp = (Exam[]) ms.getParams()[3];
				if (tmp.length < 1)
					ui.SetContent(ui.EXAMS_MANAGER_SCREEN);
				
				Exam ex = tmp[0];
				
				txtExamNum.setText(Integer.toString(ex.getExamID()));
				txtSolveTime.setText(Integer.toString(ex.getSolveTime()));
				txtTeacherComments.setText(ex.getNotesForTeacher());
				txtStudentsComments.setText(ex.getNotesForStudent());
				
				for(int i=0;i<cmbSubject.getItemCount();i++){
					if(((Subject)cmbSubject.getItemAt(i)).getId()==ex.getSubjectID()){
						cmbSubject.setSelectedIndex(i);
						break;
					}
				}
				
				for(int i=0;i<cmbCourse.getItemCount();i++){
					if(((Course)cmbCourse.getItemAt(i)).getId()==ex.getCourseID()){
						cmbCourse.setSelectedIndex(i);
						break;
					}
				}
				
				DefaultTableModel model =(DefaultTableModel) table.getModel();
				model.setRowCount(0);
				btnRemoveQuestion.setEnabled(false);
				for (Question q:ex.getQuestions()) {
					String[] row = new String[5];
					row[0] = String.format("%03d", q.getQuestionID());
					row[1] = q.getSubjectName();
					row[2] = Integer.toString(q.getPoints());
					row[3] = q.getQuestion();
					row[4] = Integer.toString(q.getId());
					model.addRow(row);
				}
				table.setModel(model);
			}
			else if (ms.getCommand().equals(CommandMessage.ACKNOWLEDGE_MESSAGE) && ((String)ms.getParams()[0]).equals(CommandMessage.ADD_EXAM)) {
				if(!Boolean.parseBoolean(ms.getParams()[2].toString()))
				{
					ui.ShowMessageBox("ERROR", "Can't add exam", JOptionPane.ERROR_MESSAGE);
					return;
				}
				else 
					ui.SetContent(ui.EXAMS_MANAGER_SCREEN);
			}
			else if (ms.getCommand().equals(CommandMessage.ACKNOWLEDGE_MESSAGE) && ((String)ms.getParams()[0]).equals(CommandMessage.EDIT_EXAM)) {
				if(!Boolean.parseBoolean(ms.getParams()[2].toString()))
				{
					ui.ShowMessageBox("ERROR", "Can't update exam", JOptionPane.ERROR_MESSAGE);
					return;
				}
				else 
					ui.SetContent(ui.EXAMS_MANAGER_SCREEN);
			}
			else if (ms.getCommand().equals(CommandMessage.ACKNOWLEDGE_MESSAGE) && ((String)ms.getParams()[0]).equals(CommandMessage.REMOVE_QUESTION_FROM_EXAM)) {
				if(!Boolean.parseBoolean(ms.getParams()[3].toString()))
				{
					ui.ShowMessageBox("ERROR", "Can't remove question from the exam", JOptionPane.ERROR_MESSAGE);
					return;
				}
				else 
					setExamID(eId);
			}
		}
	}

	/**
	 * Buttons click event handler
	 */
	@SuppressWarnings("static-access")
	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource().equals(btnCancel)) {
			// Back.
			ui.SetContent(ui.EXAMS_MANAGER_SCREEN);
		}
		else if (e.getSource().equals(btnSave)) {
			// Save.
			if (!checkValues())
				return;
			Exam ex = new Exam();
			int id=((Subject)cmbSubject.getSelectedItem()).getId()*10000 + ((Course)cmbCourse.getSelectedItem()).getId()*100 + Integer.parseInt(txtExamNum.getText());
			ex.setId(id);
			ex.setNotesForStudent(txtStudentsComments.getText());
			ex.setNotesForTeacher(txtTeacherComments.getText());
			ex.setSolveTime(Integer.parseInt(txtSolveTime.getText()));
			ex.setTeacherID(ui.getUser().getId());
			Question[] questions = null;
			DefaultTableModel model =(DefaultTableModel) table.getModel();
			int count = model.getRowCount();
			if (count > 0) {
				questions = new Question[count];
				
				for (int i = 0; i<count; i++) {
					Question q = new Question();
					q.setId(Integer.parseInt((String)model.getValueAt(i, 4)));
					q.setPoints(Integer.parseInt((String)model.getValueAt(i, 2)));
					questions[i] = q;
				}
			}
			ex.setQuestions(questions);
			CommandMessage ms;
			if (eId > 0) {
				// Update.
				ms=new CommandMessage(CommandMessage.EDIT_EXAM,new Object[]{ex});
			}
			else {
				// Add new.
				ms=new CommandMessage(CommandMessage.ADD_EXAM,new Object[]{ex});
			}
			try {
				c.sendToServer(ms);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
		else if (e.getSource().equals(btnRemoveQuestion)) {
			// Delete question.
			if (eId<1)
			{
				return;
			}
			DefaultTableModel model =(DefaultTableModel) table.getModel();
			Vector<?> o1 = (Vector<?>) model.getDataVector().get(table.getSelectedRow());
			int id = Integer.parseInt((String)o1.get(4));
			CommandMessage ms = new CommandMessage(CommandMessage.REMOVE_QUESTION_FROM_EXAM, new String[]{Integer.toString(eId), Integer.toString(id)});
			try {
				c.sendToServer(ms);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
		else if (e.getSource().equals(btnAddQuestion)) {
			// Add question.
			if (eId<1)
			{
				return;
			}
			ui.SetContent(ui.ADD_QUESTION_TO_EXAM_SCREEN);
			AddQuestionToExamUI panel= ((AddQuestionToExamUI)ui.getContentPane());
			panel.setExamID(eId);
		}
	}

	/**
	 * Question ID setter
	 * @param id Question ID
	 */
	public void setExamID(int id){
		eId=id;
		lblWarning.setVisible(false);
		cmbSubject.setEnabled(false);
		cmbCourse.setEnabled(false);
		txtExamNum.setEnabled(false);
		btnAddQuestion.setEnabled(true);
		CommandMessage ms = new CommandMessage(CommandMessage.GET_EXAMS,new String[]{"ID", Integer.toString(id)});
		try {
			c.sendToServer(ms);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void valueChanged(ListSelectionEvent arg0) {
		btnRemoveQuestion.setEnabled(true);
	}
	
	/**
	 * Validates input fields
	 * @return Validation result
	 */
	@SuppressWarnings("static-access")
	private boolean checkValues() {
		if(txtSolveTime.getText().trim().equals("") || txtExamNum.getText().trim().equals("")){
			ui.ShowMessageBox("ERROR", "Please fill all required fields", JOptionPane.ERROR_MESSAGE);
			return false;
		}
		int input;
		try {  
			input=Integer.parseInt( txtExamNum.getText() );  
		}  
		catch( Exception ex) {  
			ui.ShowMessageBox("ERROR", "Exam number must be numeric", JOptionPane.ERROR_MESSAGE);
			return false;  
		}
		if(input<1 || input>99) {
			ui.ShowMessageBox("ERROR", "Exam number must be in range 1-99", JOptionPane.ERROR_MESSAGE);
			return false;
		}
		try {  
			input=Integer.parseInt( txtSolveTime.getText() );  
		}  
		catch( Exception ex) {  
			ui.ShowMessageBox("ERROR", "Solve time number must be numeric", JOptionPane.ERROR_MESSAGE);
			return false;  
		}
		if(input<1) {
			ui.ShowMessageBox("ERROR", "Solve time must be positive", JOptionPane.ERROR_MESSAGE);
			return false;
		}
		return true;
	}
	
}
